/**
 * @Author : lizhifeng
 * @create 2022/8/10 19:53
 * @DESC 2022/8/10 19:53
 */


public class TransactionId {

    private byte[] hash;

    public TransactionId(byte[] hash) {
        this.hash = hash;
    }

    public byte[] getHash() {
        return hash;
    }

    public void setHash(byte[] hash) {
        this.hash = hash;
    }

    @Override
    public int hashCode() {
        int h = 0;
        for (int i = 0; i < hash.length; i++) {
            h = h + hash[i];
        }
        return h;
    }

    @Override
    public boolean equals(Object obj) {

        if (obj == this) {
            return true;
        }

        if (!(obj instanceof TransactionId)) {
            return false;
        }

        byte[] bytes = ((TransactionId) obj).hash;
        if (bytes.length != 32) {
            return false;
        }

        for (int i = 0; i < 32; i++) {
            if (hash[i] != bytes[i]) {
                return false;
            }
        }

        return true;
    }
}
